<style>
   .form {
        width: 60%;
        margin-left: 20%;
        margin-top: 1%;   
    }
</style>
<template>
    <div>
        <Form :model="website" class="form" label-position="right" :label-width="70"width="100%">
            <FormItem label="网站名称:">
                <Input v-model="website.name.value" size="large" :disabled="status"></Input>
            </FormItem>
            <FormItem label="启用日期:">
                <Input v-model="website.start_date.value" size="large":disabled="status"></Input>
            </FormItem>
            <FormItem label="技术支持:">
                <Input v-model="website.tecnicalSupport.value"size="large" :disabled="status"></Input>
            </FormItem>
            <FormItem label="技术支持logo:">
                <img :src="tecnicalSupportLogoUrl" />
                <UploadSingleFile v-if="!status" v-model="website.tecnicalSupportLogo.value" :format="['jpg','png']"></UploadSingleFile>
            </FormItem>
            <FormItem label="技术网址:">
                <Input v-model="website.tecnicaladdress.value"size="large" :disabled="status"></Input>
            </FormItem>
            <FormItem label="首页域名:">
                <Input v-model="website.domain.value" size="large":disabled="status"></Input>
            </FormItem>
            <FormItem label="地址:">
                <Input v-model="website.address.value" size="large":disabled="status"></Input>
            </FormItem>
            <FormItem label="邮编:">
                <Input v-model="website.zip_code.value" size="large" :disabled="status"></Input>
            </FormItem>
            <FormItem label="邮箱:">
                <Input v-model="website.email.value"size="large" :disabled="status"></Input>
            </FormItem>
            <FormItem label="联系电话:">
                <Input v-model="website.phone.value"size="large" :disabled="status"></Input>
            </FormItem>
            <FormItem label="网站备案:">
                <UE ref="ue" v-model="website.ICP.value" type="content" :disabled="status" :escape="true"></UE>
            </FormItem>
            <center><Button style="font-size:15px;width:10%" size="small" type="primary" @click="set_website()">{{ status == true ? "修改" : "提交" }}</Button></center>
        </Form>
    </div>
</template>

<script>
import UploadSingleFile from "@/common/components/UploadSingleFile";
import UE from '@/common/components/UE';

export default {
    components: {
        UploadSingleFile, UE
    },
    data () {        
        return { 
            status: true,
            website: {
                name: {},
                address: {},
                zip_code: {},
                email: {},
                phone: {},
                start_date: {},
                domain: {},
                tecnicalSupport:{},
                tecnicalSupportLogo:{ value: [] },
                tecnicaladdress:{},
                ICP:{}
            }
        }
    },
    computed: {
        tecnicalSupportLogoUrl() {
            var tl = this.website.tecnicalSupportLogo.value;
            return tl.length ? tl[0].url : "";
        }
    },
    methods: {
        set_website : function(){
            if(this.status == true){
                this.status = false;
            }
            else{
                this.api.post("free_value/set", {
                    keyvalues: {
                        "website.name": this.website.name.value,
                        "website.address": this.website.address.value,
                        "website.zip_code": this.website.zip_code.value,
                        "website.email": this.website.email.value,
                        "website.phone": this.website.phone.value,
                        "website.start_date": this.website.start_date.value,
                        "website.domain": this.website.domain.value,
                        "website.tecnicalSupport": this.website.tecnicalSupport.value,
                        "website.tecnicalSupportLogo": JSON.stringify(this.website.tecnicalSupportLogo.value),
                        "website.tecnicaladdress": this.website.tecnicaladdress.value,
                        "website.ICP": this.$refs.ue.getUEContent()
                    }
                }, res => {
                    this.$CustomMessage.success("修改成功");
                    this.status = true ;
                });
            }
        },
    },
    created() {
        this.api.post("free_value/get", {key:"website"}, res => {
            var tl = res.data.tecnicalSupportLogo;
            if(tl) {
                tl.value = JSON.parse(tl.value);
            }
            Object.assign(this.website, res.data);
        });
    }  
}
</script>
